const path = require('path')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')

module.exports = {
  mode: 'production',

  output: {
    path: path.resolve(__dirname, '../dist'),
    filename: '[name]-[contenthash:10].js'
  },

  module: {
    rules: [
      {
        test: /\.(png|svg|jpg|jpeg|gif)$/i,
        type: 'asset/resource',
        generator: {
					filename: 'images/img-[contenthash:10][ext]'  // 单独指定 名字
				}
      },
    ]
  },

  plugins: [
    new CleanWebpackPlugin(),

    new MiniCssExtractPlugin({
      filename: ({ chunk }) => {
        return `${chunk.name.replace('js/', 'css/')}-[contenthash:10].css`
      },
    })
  ],
}